package com.butterfly.hotkey.core.model;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.group.ChannelGroup;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.util.concurrent.GlobalEventExecutor;

/**
 * @author butterfly
 */
public class AppInfoModel {

    /**
     * 名称
     */
    private String name;

    /**
     * 所有关联的渠道
     */
    private ChannelGroup channelGroup;

    public AppInfoModel(String name) {
        this.name = name;
        channelGroup = new DefaultChannelGroup(name, GlobalEventExecutor.INSTANCE);
    }

    public void writeAndFlush(Object object) {
        channelGroup.writeAndFlush(object);
    }

    public void add(ChannelHandlerContext ctx) {
        channelGroup.add(ctx.channel());
    }

    public void remove(ChannelHandlerContext ctx) {
        channelGroup.remove(ctx.channel());
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public ChannelGroup getChannelGroup() {
        return channelGroup;
    }

    public void setChannelGroup(ChannelGroup channelGroup) {
        this.channelGroup = channelGroup;
    }
}
